home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / cc.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  12KB  |  316 lines

  1. /* FILE:         cc.c
  2.  * DATE:         27-Jan-1987
  3.  *               Updated 07-01-1987 to allow wildcards and linking multiple
  4.  *               files.
  5.  *               Updated 27-01-1987 to allow assembling and/or compiling and
  6.  *               to allow linking without compiling.
  7.  * AUTHOR:       Robert Royar rdroya01@bitnet
  8.  * SYSTEM:       Atari ST
  9.  * COMPILER:     Alcyon v. 4.14
  10.  * PURPOSE:      A simple minded compiler driver, no frills. (well, almost)
  11.  * USAGE:        cc filename[s] (path must agree with cc.ini)
  12.  *               the command line may contain wildcards as long as all
  13.  *               source files are on the drive designated as the sdir in
  14.  *               this file.  Using the link option will cause the linker to
  15.  *               look for a command file on the source directory.  That link
  16.  *               file should be named `foo.lnk' where `foo' is the name in
  17.  *               the cc.ini file associated with the lnkfile value.  The
  18.  *               link file should tell the linker to place the output on the
  19.  *               source dir if the relocation program is to find the
  20.  *               `foo.68k' file and successfully create a `foo.prg' file.
  21.  *               Calling the program without a command line and with dolink=1
  22.  *               will force it to try to link the file `linkfile.68k' and
  23.  *               then call relmod.  Giving it a filename with an .s extent
  24.  *               will skip the compiling and assemble the file.  Files with
  25.  *               .s extents and .c extents may be mixed on a line.
  26.  * DISTRIBUTION: Public Domain.  Do with it what you will.  Just leave
  27.  *               the header intact.
  28.  */
  29. #include <stdio.h>
  30. #include <osbind.h>
  31. #include <ctype.h>
  32. #include <errno.h>
  33.  
  34. unsigned long _STKSIZ = 16284;  /* keep 16K */
  35.  
  36. /* These are the defaults.  All of them can be over-ridden by values
  37.  * in the cc.ini file if that file is on the default drive and directory.
  38.  */
  39. char sdir[81] = "e:\\"; /* where the source files are */
  40. char include[81] = "d:\\stdlib.h\\"; /* include files */
  41. char tdir[81] = "m:\\"; /* temporary files (all of them) */
  42. char bin[81] = "c:\\bin\\";     /* compiler directory */
  43. char symb[81] = "c:\\bin\\";    /* as68 symbols */
  44. char floflag[12] = " ";         /* float ?      */
  45. char delflag[12] = "1";         /* delete temporary files */
  46. char lnkflag[12] = "0";         /* link file[s] if == "1" */
  47. char warn[12] = " ";            /* make it -w to suppress warnings */
  48. char syslib[81] = "c:\\bin\\";  /* drive to log for linker */
  49. char lnk[81] = "out";           /* .68K and .lnk filename */
  50. char fprg[81] = "out";          /* final output name */
  51. char pname[81];
  52. char command[81];
  53. char source[81];
  54. int temdrv;
  55. char delfile[80];
  56. int delete = 1;
  57. int dolink = 0;
  58. int doasm  = FALSE;
  59. char path[128];
  60. int exec;
  61. int curdrv;
  62. char author[30] = "Robert Royar";
  63.  
  64. main(argc,argv)
  65. register int argc;
  66. char *argv[];
  67. {
  68.         register char c, *ptr;
  69.         register int argnum;
  70.         char *index();
  71.  
  72.         argnum = 1;
  73.         curdrv = (int)Dgetdrv(); /* 0 = A */
  74.         Dgetpath(path,(1+curdrv)); /* 1 = A */
  75.         if (access("cc.ini",4) != -1)
  76.                 if (!inivar())
  77.                         exit(-1);
  78.         if (argc == 1 && dolink == FALSE)
  79.                 {
  80.                 fprintf(stderr,"usage: %s filename[s]\n",argv[0]);
  81.                 exit(-1);
  82.                 }
  83.         if (argc == 1)
  84.                 {
  85.                 exec = linkfil();
  86.                 goto out;
  87.                 }
  88.         if (tdir[1] == ':')
  89.                 {
  90.                 c = (char)toupper(tdir[0]);
  91.                 temdrv = (int)(c - 'A');
  92.                 Dsetdrv(temdrv);        /* Log into temp drive */
  93.                 }
  94.         if((exec=(int)Dsetpath(tdir))!=0)
  95.                 goto out;
  96.         while(--argc)
  97.                 {
  98.                 strcpy(source,argv[argnum++]);
  99.                 if ((ptr=index(source,':'))!=NULL)
  100.                         strcpy(source,++ptr);
  101.                 /* If the file has an .s extent, then assemble it.
  102.                  * Check the source dir first.  If it's not there,
  103.                  * check the temp dir.  Set the doasm flag to fit
  104.                  * the outcome, or break if no file found.
  105.                  */
  106.                 if ((ptr=index(source,'.'))!=NULL)
  107.                         {
  108.                         *ptr = '\0';    /* don't let the extension through */
  109.                         /* delete any existing .o files */
  110.                         sprintf(delfile,"%s%s.o",tdir,source);
  111.                         if (access(delfile,4)==NULL)
  112.                                 unlink(delfile);
  113.                         ++ptr;
  114.                         if (*ptr != '\0')
  115.                                 {
  116.                                 *ptr = tolower(*ptr);
  117.                                 if (strcmp(ptr,"s")==NULL) /* assemb only */
  118.                                         {
  119.                                         sprintf(command,"%s%s.s",sdir,source);
  120.                                         if ((exec=access(command,4)) == -1)
  121.                                                 {
  122.                                                 sprintf(command,"%s%s.s",
  123.                                                        tdir,source);
  124.                                                 if ((exec=access(command,4))
  125.                                                      == -1)
  126.                                                         continue;
  127.                                                 else /* this is a tdir file */
  128.                                                         doasm = FALSE;
  129.                                                 }
  130.                                         else    /* this asm file is on sdir */
  131.                                                 doasm = TRUE;
  132.                                         if ((exec=as())!=NULL)
  133.                                                 goto out;
  134.                                         else
  135.                                                 continue;
  136.                                         }
  137.                                 }
  138.                         }
  139.                 /* delete any existing .o files */
  140.                 sprintf(delfile,"%s%s.o",tdir,source);
  141.                 if (access(delfile,4)==NULL)
  142.                         unlink(delfile);
  143.                 doasm = FALSE;
  144.                 sprintf(command,"%s%s.c",sdir,source);
  145.                 if ((exec=access(command,4)) == -1)
  146.                         break;
  147.                 if ((exec=cc())!=NULL)
  148.                         break;
  149.                 }
  150.         if (dolink && (exec == NULL))
  151.                 exec = linkfil();
  152. out:    Dsetdrv(curdrv);
  153.         Dsetpath(path);
  154.         exit(exec);
  155. }
  156.  
  157. cc()
  158. {
  159.         fprintf(stderr,"\nCompiling : %s%s.c\n",sdir,source);
  160.         sprintf(&command[1],"-i %s %s%s.c %s%s.i ",
  161.                 include,sdir,source,tdir,source);
  162.         command[0] = (char)strlen(&command[1]);
  163.         sprintf(pname,"%sCP68.PRG",bin);
  164.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  165.                 return(exec);
  166.         sprintf(&command[1],"%s%s.i %s%s.1 %s%s.2 %s%s.3 %s %s",
  167.                 tdir,source,tdir,source,tdir,source,tdir,source,floflag,warn);
  168.         command[0] = (char)strlen(&command[1]);
  169.         sprintf(pname,"%sC068.PRG",bin);
  170.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  171.                 return(exec);
  172.         if (delete)
  173.                 {
  174.                 sprintf(command,"%s%s.i",tdir,source);
  175.                 unlink(command);
  176.                 }
  177.         sprintf(&command[1],"%s%s.1 %s%s.2 %s%s.s",
  178.         tdir,source,tdir,source,tdir,source);
  179.         command[0] = (char)strlen(&command[1]);
  180.         sprintf(pname,"%sC168.PRG",bin);
  181.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  182.                 return(exec);
  183.         sprintf(command,"%s%s.1",tdir,source);
  184.         unlink(command);
  185.         sprintf(command,"%s%s.2",tdir,source);
  186.         unlink(command);
  187.         exec = as();
  188.         return(exec);
  189. }
  190.  
  191. as()
  192. {
  193.         if (!doasm)
  194.                 {
  195.                 fprintf(stderr,"\nAssembling : %s%s.s\n",tdir,source);
  196.                 sprintf(&command[1],"-l -u -s %s %s%s.s",bin,tdir,source);
  197.                 }
  198.